
<?php
//确保在连接客户端时不会超时  
set_time_limit(0);
 
//设置IP和端口号  
$address='127.0.0.1';
$port=843;    //调试的时候，可以多换端口来测试程序！  
 
//创建一个SOCKET  
if(($sock=socket_create(AF_INET,SOCK_STREAM,SOL_TCP))<0)
{
	echo "socket_create() 失败的原因是:".socket_strerror($sock)."<br>";  
}

//绑定到socket端口  
if(($ret=socket_bind($sock,$address,$port))<0)
{
	echo "socket_bind() 失败的原因是:".socket_strerror($ret)."<br>";  
}

//开始监听  
if(($ret=socket_listen($sock,4))<0)
{
	echo "socket_listen() 失败的原因是:".socket_strerror($ret)."<br>";  
}

$policyFile = "<?xml version='1.0'?>";
$policyFile.="<cross-domain-policy>";
$policyFile.="<site-control permitted-cross-domain-policies='all'/>";
$policyFile.="<allow-access-from domain='192.168.1.90' to-ports='10000' />";
$policyFile.="</cross-domain-policy>";

do {
	if (($msgsock = socket_accept($sock)) < 0)
	{
		echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n";
		break;
	}

	//发到客户端  
	//$msg ="<font color=red>欢迎进入服务器！</font><br>";  
	//socket_write($msgsock, $msg, strlen($msg));

	echo "read info from client<br>";
	$buf = socket_read($msgsock,128);
	echo $buf;
	$index=strpos($buf,"policy-file-request");
	if($index){
		socket_write($msgsock, $policyFile, strlen($policyFile));
	}
	socket_close($msgsock);
} while (true);

socket_close($sock);
?>